﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace com.sharepointutils.application
{
    class FormUtilities
    {
        public static void OpenListNode(TreeNode node, SharePointConnection connection)
        {
            if (node != null)
            {
                if (node.Tag is Microsoft.SharePoint.Client.List)
                {
                    connection.List = node.Text;
                }

                if (node.Tag is SiteInformation)
                {
                    SiteInformation info = node.Tag as SiteInformation;
                    connection.URL = info.URL;
                    connection.Credentials = info.Credentials;
                    connection.SiteName = info.SiteName;
                }
                else
                {
                    if (node.Parent != null)
                    {
                        FormUtilities.OpenListNode(node.Parent, connection);
                    }
                    else
                    {
                        throw new Exception("Could not open list");
                    }
                }
            }
        }

    }
}
